Skip to content

fix(app-logic): create the write backup exclusively - #1771

Open
smart-ssh-coder[bot] wants to merge 1 commit into
developfrom
issue-1735-backup-before-a-file-write-create-the
Open

smart-ssh-coder[bot] wants to merge 1 commit into
developfrom
issue-1735-backup-before-a-file-write-create-the

Conversation

@smart-ssh-coder

Copy link
Copy Markdown
Contributor

Closes #1735

Summary

copy_to_backup now creates the backup with create_file_exclusive first and only then marks it as created (cleanup-eligible); chunk writes use truncate = false. A name collision or symlink at the backup name fails the write before the target is touched, and nothing at that name is modified or removed. A failure after the create still removes the partial backup.

Acceptance Criteria

  • Existing file at backup name fails, file unchanged/not removed, target untouched: met — remote_files.rs:backup_tests::test_backup_onto_an_existing_name_fails_and_keeps_that_file
  • Symlink not followed/removed: met — local_sftp.rs:test_create_file_exclusive_does_not_follow_a_symlink (the mock has no symlink model; a file at the name exercises the same exclusive-create path)
  • Failing first chunk removes partial backup: met — tests_activity.rs:test_backup_failing_on_the_first_write_removes_the_partial_backup (unchanged)
  • Empty source gets empty exclusive backup: met — remote_files.rs:backup_tests::test_empty_backup_is_created_exclusively, tests_activity.rs:test_backup_of_an_empty_file_is_an_empty_file
  • Mock supports the call sequence: met — existing mock create_file_exclusive suffices; existing tests pass unchanged
  • Tests pass: met (cargo test -p app-logic --lib backup, -p ssh-transport)

Tests

Counter-proof: with the exclusive create disabled, the collision, empty-backup and existing empty-file tests fail.

Assumptions

  • Name collision (same second) fails the write, no retry (recommended option in the issue).

Spec: updated 0020 (§4.2.4)
Threat model: no change – only makes the backup creation stricter; no new surface.

Manual test steps

None.

Follow-ups

None.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backup before a file write: create the backup exclusively and never remove a foreign file

0 participants